/*
 * Copyright (C) 2004, Velocityme Partnership
 * TaskStateMachineValueActionForm.java
 *
 * Created on 09 October 2004, 02:34
 */

package com.velocityme.www.actionforms.nodeactionforms;

import com.velocityme.entity.Role;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.apache.struts.action.ActionMapping;


/**
 *
 * @author  Robert
 */
public class TaskStateMachineValueActionForm extends NodeValueActionForm {
    
    private Collection<Long> m_unassignedRoleIds;
    private Collection<Long> m_interestedRoleIds;
    
    /** Creates a new instance of TaskStateMachineValueActionForm */
    public TaskStateMachineValueActionForm() {
    }
    
    public void reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest request) {
        m_interestedRoleIds = new ArrayList<Long>();
    }
    
    public Collection<Long> getUnassignedRoleIds() {
        return m_unassignedRoleIds;
    }
    
    public void setUnassignedRoleIds(Collection<Long> unassignedRoleIds) {
        m_unassignedRoleIds = unassignedRoleIds;
    }
    
    public Collection<Long> getInterestedRoleIds() {
        return m_interestedRoleIds;
    }
    
    public void setInterestedRoleIds(Collection<Long> interestedRoleIds) {
        m_interestedRoleIds = interestedRoleIds;
    }
    
    public Collection<Role> getInterestedRoles(Collection<Role> allRoles) {
        Map<Long,Role> roleMap = new HashMap();
        for (Role role: allRoles) {
            roleMap.put(role.getId(), role);
        }
        Collection<Role> roles = new ArrayList<Role>();
        for (Long id: m_interestedRoleIds) {
            roles.add(roleMap.get(id));
        }
        return roles;
    }
    
}
